    /*每个关卡循环的次数 */
     var i=0;
     /*出现的位置 */
     var num;
     /*限制积分重复增加 */
     var limitRepeats=false;
     /* 累计的积分 */
     var integratingIntegral=0;
     /* 第几个关卡*/
     var level=1;
     /*记录数据 */
     var levelData=new Array();
     /* 循环主体 */
     function start (){
    	/*产生一个0-9的随机数 */
         num=Math.floor(Math.random()*9)+1;
    	 document.getElementById(num).getElementsByTagName("img")[0].setAttribute("src","static/img/1.jpg");
    	 limitRepeats=true;
    	 setTimeout(function(){
    		 document.getElementById(num).getElementsByTagName("img")[0].setAttribute("src","static/img/2.jpg");
    		 i++;
    		 if(i<10){
    			 limitRepeats=false;
    			 start(); 
    		 }else{
    		  var integral=parseInt(document.getElementById("integral").innerText);
    		  document.getElementById("pPBox").style.display="block";
    		  document.getElementById("gameBody").style.display="none";
    		  if(integral>=5*level){
    			  document.getElementById("boxBody").innerHTML="总结分:"+integratingIntegral;
    		  }else{
    			  document.getElementById("boxBody").innerHTML="哈哈哈";
    			  document.getElementById("next").style.display="none";
    		  }
    		 }
    	 },3000-level*500);
     };
     /*鼠标点击操作方法 */
     function clickEle(e){
    	 var targ
    	 if (!e) {
    		 var e = window.event
    	 }
    	 if (e.target){
    		 targ = e.target
    		 }else if (e.srcElement){ 
    		 targ = e.srcElement
    	}
    	if((num==parseInt(targ.id)||num==parseInt(targ.alt))&&limitRepeats){
    		integratingIntegral++;
    		limitRepeats=false;
    	}
    	document.getElementById("integral").innerText=integratingIntegral;
     }
     /* 下 一关*/
     function next(){
    	  //记录数据: 关卡  积分  时间
		 var singleLevelData={};
		 singleLevelData.level=level;
		 singleLevelData.integratingIntegral=integratingIntegral;
		 singleLevelData.time=new Date();
		 levelData.push(singleLevelData);
		 document.getElementById("level").innerText=level;
    	 level++;
    	 document.getElementById("integral").innerText=integratingIntegral;
    	 document.getElementById("pPBox").style.display="none";
    	 document.getElementById("gameBody").style.display="block";
    	 i=0;
    	 start();
     }
    /*重新开始*/
     function restart(){
    	 var affirm=confirm("你确定要重新");
    	 if(affirm){
    	 i=0;
         limitRepeats=false;
         integratingIntegral=0;
         level=1;
     	for(var j=0;j<document.getElementById("tbody").getElementsByTagName("td").length;j++){
    		document.getElementById("tbody").getElementsByTagName("td")[j].style.color="black";
    	 }
         document.getElementById("level").innerText=level;
         document.getElementById("integral").innerText=integratingIntegral;
    	 document.getElementById("pPBox").style.display="none";
    	 document.getElementById("gameBody").style.display="block";
    	 start();
    	 }
     }
   /*重玩本关 */
     function restartNow(){
    	 i=0;
    	 limitRepeats=false;
    	 if(levelData.length>0){
    	 integratingIntegral=levelData[levelData.length-1].integratingIntegral;
    	 }else{
         integratingIntegral=0;
    	 }
    	 document.getElementById("level").innerText=level;
    	 document.getElementById("integral").innerText=integratingIntegral;
    	 document.getElementById("pPBox").style.display="none";
    	 document.getElementById("gameBody").style.display="block";
    	 start();
     }
    /*结束*/
    function end(){
    	window.location.href="index.jsp";
     }
    /*暂停*/
    function stop(){
    	document.cookie="level="+level;
    	document.cookie="i="+i;
    	document.cookie="integratingIntegral="+integratingIntegral;
    	document.getElementById("pause").style.display="block";
     }
    /*暂停后开始 */
    function restartAfterStop(){
    	document.getElementById("pause").style.display="none";
    	if(getCookie("level").length>0){
    		level=parseInt(getCookie("level")[getCookie("level").length-1]);
        	i=parseInt(getCookie(" i")[getCookie(" i").length-1]);
        	integratingIntegral=parseInt(getCookie(" integratingIntegral")[getCookie(" integratingIntegral").length-1]);
    	}
    	for(var j=0;j<document.getElementById("tbody").getElementsByTagName("td").length;j++){
    		document.getElementById("tbody").getElementsByTagName("td")[j].style.color="black";
    	}
    	document.getElementById("level").innerText=level;
   	    document.getElementById("integral").innerText=integratingIntegral;
    	start();
    }
    /*通过名称获得cookie值 */
    function getCookie(name){
	    var nameValueA=new Array();
    	var cookieValue=document.cookie
    	var cookieA=cookieValue.split(/=|;/);
    	for(var j=0;j<cookieA.length;j+=2){
    		if(cookieA[j]==name){
    			nameValueA.push(cookieA[j+1]);
    		}
    	}
    	return nameValueA;
    }